package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import com.sky.entity.Category;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 新增分类
     *
     * @param category
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
            " VALUES" +
            " (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Category category);

    /**
     * 判断菜品名称是否重复
     *
     * @param name
     * @return
     */
    @Select("select count(*) from category where name = #{name}")
    long getCountByName(String name);

    /**
     * 分页查询分类列表
     *
     * @param pageQueryDTO
     * @return
     */
    Page<Category> getCategoryList(CategoryPageQueryDTO pageQueryDTO);

    /**
     * 根据id删除分类
     *
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    /**
     * 更新分类
     *
     * @param category
     */
    void update(Category category);

    /**
     * 菜品分类的启用和停用
     *
     * @param status
     * @param id
     */
    @Update("update category set status = #{status} where id = #{id}")
    void startOrStop(@Param("status") Integer status, @Param("id") Long id);

    /**
     * 根据类型查询分类
     *
     * @param type
     * @return
     */
    List<Category> list(Integer type);

    /**
     * 根据id查询分类
     *
     * @param id
     * @return
     */
    @Select("select * from category where id = #{id}")
    Category getCategoryById(Long id);

    /**
     * 根据名称获取分类id
     *
     * @param dishCategoryName
     * @return
     */
    @Select("select * from category where name=#{dishCategoryName};")
    Category getCategoryIdByName(String dishCategoryName);
}
